import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream; 

public class AntZip{ 
    private ZipFile        zipFile; 
    private ZipOutputStream zipOut;    //压缩Zip 
    private ZipEntry        zipEntry; 
    private static int      bufSize;    //size of bytes 
    private byte[]          buf; 
    private int            readedBytes; 
    
    public AntZip(){ 
        this(512); 
    } 

    public AntZip(int bufSize){ 
        this.bufSize = bufSize; 
        this.buf = new byte[this.bufSize]; 
    } 


    //解压指定zip文件 
    public void unZip(String unZipfileName){//unZipfileName需要解压的zip文件名 
        FileOutputStream fileOut; 
        File file; 
        InputStream inputStream; 

        try{ 
            this.zipFile = new ZipFile(unZipfileName); 

            for(Enumeration entries = this.zipFile.entries(); entries.hasMoreElements();){ 
                ZipEntry entry = (ZipEntry)entries.nextElement(); 
                file = new File(entry.getName()); 

                if(entry.isDirectory()){ 
                    file.mkdirs(); 
                } 
                else{ 
                    //如果指定文件的目录不存在,则创建之. 
                    File parent = file.getParentFile(); 
                    if(!parent.exists()){ 
                        parent.mkdirs(); 
                    } 

                    inputStream = zipFile.getInputStream(entry); 

                    fileOut = new FileOutputStream(file); 
                    while(( this.readedBytes = inputStream.read(this.buf) ) > 0){ 
                        fileOut.write(this.buf , 0 , this.readedBytes ); 
                    } 
                    fileOut.close(); 

                    inputStream.close(); 
                }    
            } 
            this.zipFile.close(); 
        }catch(IOException ioe){ 
            ioe.printStackTrace(); 
        } 
    } 

    //设置缓冲区大小 
    public void setBufSize(int bufSize){ 
        this.bufSize = bufSize; 
    } 

    //测试AntZip类 
    public static void main(String[] args)throws Exception{ 
            AntZip zip = new AntZip(); 

                zip.unZip("f:\\南京市数据.tmp"); 
 
       
    } }